Skip to content

Conversation

gmazzamuto
Copy link
Contributor

Hi all! First of all my congrats for Backpex!

Here is a PR with some enhancements:

  • the first commit is the simplest, it just replaces a complicated Enum.reduce followed by Enum.reverse with a single call to Enum.filter
  • the other commits add support for option groups in the Select and MultiSelect fields. Option groups are already supported by Phoenix via Phoenix.HTML.Form.options_for_select/2, but don't work out of the box in Backpex. The changes for Select are a simple fix, the implementation for MultiSelect is just a bit more complicated. See below for some screenshots.

I have made other small improvements if you are interested!

Option groups in Select (as seen in Firefox):

  • Screenshot_20250918_225026

Option groups in MultiSelect:

  • Screenshot_20250918_225138

One can simply call `Enum.filter`, instead of a more complicated
`Enum.reduce` followed by `Enum.reverse`.
Conversion to string was missing in the else case (the option value
could be an atom, therefore it must be converted to a string for proper
filtering).
See Phoenix.HTML.Form.options_for_select/2
Additionally, this fixes the `:options` field option not working when
passed a list rather than a function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant